package threading;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: xwl
 * Date: 2023-08-09
 * Time: 21:10
 */
// 单例类(饿汉模式)
class Singleton {
    // 唯一实例的本体
    private static Singleton instance = new Singleton();
    // 获取实例的方法
    public static Singleton getInstance() {
        return instance;
    }
    // 私有化构造方法,可以禁止外部new实例
    private Singleton () {}
}

public class ThreadDemo14 {
    public static void main(String[] args) {
        // 此时 s1 和 s2 是同一个对象
        Singleton s1 = Singleton.getInstance();
        Singleton s2 = Singleton.getInstance();


    }
}
